/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.joseph.model;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.Blob;
import javax.imageio.ImageIO;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.swing.ImageIcon;

/**
 *
 * @author Joseph
 */
@Entity
@Table
@NamedQueries({@NamedQuery(name="Student.getAll",query="SELECT e FROM Student e")})
public class Student implements Serializable{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column
    private int studentId;
    @Column
    private String firstname;
    @Column
    private String lastname;
    @Column
    private int yearLevel;
    @Lob
    @Column(name = "foto")
    private byte[] foto;
    
    @Column
    private String nombre_img;

    public String getNombre_img() {
        return nombre_img;
    }

    public void setNombre_img(String nombre_img) {
        this.nombre_img = nombre_img;
    }

    public Student(int studentId, String firstname, String lastname, int yearLevel, byte[] foto, String nombre_img) {
        this.studentId = studentId;
        this.firstname = firstname;
        this.lastname = lastname;
        this.yearLevel = yearLevel;
        this.foto = foto;
        this.nombre_img = nombre_img;
    }
    
    
    
    
    public byte[] getFoto() {
          
        return foto;
    }

    public void setFoto(byte[] foto) {
        this.foto = foto;
    }
    
    

    public Student(int studentId, String firstname, String lastname, int yearLevel, byte[] foto) {
        this.studentId = studentId;
        this.firstname = firstname;
        this.lastname = lastname;
        this.yearLevel = yearLevel;
        this.foto = foto;
        
    }

   

    public Student(byte[] foto) {
        this.foto = foto;
    }
    
    
    
   public static BufferedImage  byteArrayToImage(byte[] foto){  
        BufferedImage bufferedImage=null;
        try {
            InputStream inputStream = new ByteArrayInputStream(foto);
            bufferedImage = ImageIO.read(inputStream);
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
        return bufferedImage;
}
    

    public int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public int getYearLevel() {
        return yearLevel;
    }

    public void setYearLevel(int yearLevel) {
        this.yearLevel = yearLevel;
    }

    public Student(int studentId, String firstname, String lastname, int yearLevel) {
        this.studentId = studentId;
        this.firstname = firstname;
        this.lastname = lastname;
        this.yearLevel = yearLevel;
    }
    
    public Student(){}
}
